home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / DataSources / ColdFusion / ConnectionVar.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  7.7 KB  |  290 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3.  
  4. //************** GLOBALS VARS *****************
  5.  
  6. var CONNECTIONVAR_FILENAME = "REQ_D.gif";
  7. var DATASOURCELEAF_FILENAME = "DSL_D.gif";
  8.  
  9.  
  10. //****************** API **********************
  11.  
  12. //--------------------------------------------------------------------
  13. // FUNCTION:
  14. //   addDynamicSource
  15. //
  16. // DESCRIPTION:
  17. //   Adds a Dynamic Source to the Data Bindings panel
  18. //
  19. // ARGUMENTS:
  20. //   defaultName - string - (optional) name to display
  21. //
  22. // RETURNS:
  23. //   nothing
  24. //--------------------------------------------------------------------
  25.  
  26. function addDynamicSource(defaultName)
  27. {
  28.   var retVal = false;
  29.   
  30.   var siteURL = dw.getSiteRoot();
  31.   if (siteURL.length)
  32.   {
  33.     var currList = dwscripts.getListValuesFromNote(siteURL,"ConnectionVar");
  34.     var nameList = new Array();
  35.     for (var i=0; i < currList.length; i++)
  36.     {
  37.       nameList.push(currList[i].split(";")[0]);
  38.     }
  39.     
  40.     var args = new Object();
  41.     args.defaultName = defaultName;
  42.     args.nameList = nameList;
  43.     
  44.     var info = dwscripts.callCommand("ConnectionVariable", args);
  45.     if (info)
  46.     {
  47.       var success = dwscripts.addListValueToNote(siteURL, "ConnectionVar", info.name + ";" + info.dataSource, true);
  48.       if (success)
  49.       {
  50.         retVal = true;
  51.       }
  52.     }
  53.   }
  54.   else
  55.   {
  56.     alert(MM.MSG_DefineSite);
  57.   }
  58.   
  59.   return retVal;
  60. }
  61.  
  62.  
  63. //--------------------------------------------------------------------
  64. // FUNCTION:
  65. //   findDynamicSources
  66. //
  67. // DESCRIPTION:
  68. //   Returns a list of Dynamic Sources on the page
  69. //
  70. // ARGUMENTS:
  71. //   none
  72. //
  73. // RETURNS:
  74. //   JavaScript Array of Objects
  75. //--------------------------------------------------------------------
  76.  
  77. function findDynamicSources()
  78. {
  79.   var retList = new Array();
  80.  
  81.   var siteURL = dw.getSiteRoot()
  82.  
  83.   if (siteURL.length)
  84.   {
  85.     var bindingsArray = dwscripts.getListValuesFromNote(siteURL, "ConnectionVar");
  86.     if (bindingsArray.length > 0)
  87.     {
  88.       retList.push(new DataSource(MM.LABEL_ConnectionVar, 
  89.                                   CONNECTIONVAR_FILENAME, 
  90.                                   false, 
  91.                                   "ConnectionVar.htm"))
  92.     }
  93.   }
  94.  
  95.   return retList;
  96. }
  97.  
  98.  
  99. //--------------------------------------------------------------------
  100. // FUNCTION:
  101. //   generateDynamicSourceBindings
  102. //
  103. // DESCRIPTION:
  104. //   Returns a list of bindings for the given elementName on the page.
  105. //
  106. // ARGUMENTS:
  107. //   sourceName - string - the name returned from the findDynamicSources
  108. //     function
  109. //
  110. // RETURNS:
  111. //   JavaScript Array of Objects
  112. //--------------------------------------------------------------------
  113.  
  114. function generateDynamicSourceBindings(sourceName)
  115. {
  116.   var retVal = new Array();
  117.  
  118.   var siteURL = dw.getSiteRoot();
  119.   if (siteURL.length)
  120.   {
  121.     var bindingsArray = dwscripts.getListValuesFromNote(siteURL, "ConnectionVar");
  122.     
  123.     for (var i=0; i < bindingsArray.length; i++)
  124.     {
  125.       var info = bindingsArray[i].split(";");
  126.       
  127.       if (info && info.length == 2)
  128.       {
  129.         retVal.push(new DataSource(info[0],DATASOURCELEAF_FILENAME,true,"ConnectionVar.htm",info[1]));
  130.       }
  131.     }
  132.   }
  133.  
  134.   return retVal;
  135. }
  136.  
  137.  
  138. //--------------------------------------------------------------------
  139. // FUNCTION:
  140. //   generateDynamicDataRef
  141. //
  142. // DESCRIPTION:
  143. //   Returns a dynamic binding string.
  144. //
  145. // ARGUMENTS:
  146. //   sourceName - string - the name of the dynamic source returned
  147. //     from the findDynamicSources function
  148. //   bindingName - string - the name of a dynamic source binding returned
  149. //     from generateDynamicSourceBindings
  150. //
  151. // RETURNS:
  152. //   string - the code to insert on the page
  153. //--------------------------------------------------------------------
  154.  
  155. function generateDynamicDataRef(sourceName, bindingName, dropObject)
  156. {
  157.   var paramObj = new Object();
  158.   paramObj.bindingName = bindingName;
  159.   var retStr = extPart.getInsertString("", "ConnectionVar_DataRef", paramObj);
  160.  
  161.   // We need to strip the cfoutput tags if we are inserting into a CFOUTPUT tag
  162.   // or binding to the attributes of a ColdFusion tag.
  163.   if (dwscripts.canStripCfOutputTags(dropObject, true))
  164.   {
  165.     retStr = dwscripts.stripCFOutputTags(retStr, true);
  166.   } 
  167.  
  168.   return retStr;
  169. }
  170.  
  171.  
  172. //--------------------------------------------------------------------
  173. // FUNCTION:
  174. //   inspectDynamicDataRef
  175. //
  176. // DESCRIPTION:
  177. //   Inspects a dynamic binding string and returns a pair of 
  178. //   source and binding values.
  179. //
  180. // ARGUMENTS:
  181. //   expression - string - the dynamic binding expression to be
  182. //     inspected
  183. //
  184. // RETURNS:
  185. //   JavaScript Array of strings - an array of length 2, with the first
  186. //   value being the sourceName, and the second being the bindingName
  187. //--------------------------------------------------------------------
  188.  
  189. function inspectDynamicDataRef(expression)
  190. {
  191.   var retArray = new Array();
  192.  
  193.   if(expression.length)
  194.   {
  195.     var params = extPart.findInString("ConnectionVar_DataRef", expression);
  196.     if (params)
  197.     {
  198.       retArray[0] = MM.LABEL_ConnectionVar;
  199.       retArray[1] = params.bindingName;
  200.     }
  201.   }
  202.     
  203.   return retArray;
  204. }
  205.  
  206.  
  207. //--------------------------------------------------------------------
  208. // FUNCTION:
  209. //   editDynamicSource
  210. //
  211. // DESCRIPTION:
  212. //   edits a dynamic source from the document.
  213. //
  214. // ARGUMENTS:
  215. //   sourceName - a data source name
  216. //   bindingName - one of the bindings for that data source
  217. //
  218. // RETURNS:
  219. //   nothing
  220. //--------------------------------------------------------------------
  221. function editDynamicSource(sourceName, bindingName)
  222. {
  223.   retVal = false;
  224.   
  225.   var siteURL = dw.getSiteRoot();      
  226.   if (siteURL.length && bindingName)
  227.   {
  228.     var bindingsArray = dwscripts.getListValuesFromNote(siteURL, "ConnectionVar");
  229.     var index = dwscripts.findInArray(bindingsArray, bindingName,
  230.          new Function ("arrayVal, searchVal","return (arrayVal.indexOf(searchVal) == 0);"));
  231.     if (index != -1)
  232.     {
  233.       var info = bindingsArray[index].split(";");
  234.       
  235.       if (info.length >= 2)
  236.       {      
  237.         var args = new Object();
  238.         args.name = info[0];
  239.         args.dataSource = info[1];
  240.  
  241.         var info = dwscripts.callCommand("ConnectionVariable", args);
  242.         if (info)
  243.         {
  244.           dwscripts.deleteListValueFromNote(siteURL, "ConnectionVar", bindingsArray[index]);
  245.           var success = dwscripts.addListValueToNote(siteURL, "ConnectionVar", info.name + ";" + info.dataSource, true);
  246.           if (success)
  247.           {
  248.             retVal = true;
  249.           }
  250.         }
  251.       }
  252.     }
  253.   }
  254.   
  255.   return retVal;
  256. }
  257.  
  258.  
  259. //--------------------------------------------------------------------
  260. // FUNCTION:
  261. //   deleteDynamicSource
  262. //
  263. // DESCRIPTION:
  264. //   Deletes a dynamic source from the document.
  265. //
  266. // ARGUMENTS:
  267. //   sourceName - string - the name of the dynamic source returned
  268. //     from the findDynamicSources function
  269. //   bindingName - string - the name of a dynamic source binding returned
  270. //     from generateDynamicSourceBindings
  271. //
  272. // RETURNS:
  273. //   nothing
  274. //--------------------------------------------------------------------
  275.  
  276. function deleteDynamicSource(sourceName, bindingName)
  277. {
  278.   var siteURL = dw.getSiteRoot();      
  279.   if (siteURL.length)
  280.   {
  281.     var bindingsArray = dwscripts.getListValuesFromNote(siteURL, "ConnectionVar");
  282.     var index = dwscripts.findInArray(bindingsArray, bindingName,
  283.          new Function ("arrayVal, searchVal","return (arrayVal.indexOf(searchVal) == 0);"));
  284.     if (index != -1)
  285.     {
  286.       dwscripts.deleteListValueFromNote(siteURL, "ConnectionVar", bindingsArray[index]);
  287.     }
  288.   }
  289. }
  290.